package com.hhq.sso.system;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.FileCopyUtils;

import java.io.InputStreamReader;

/**
 * <p>
 * Description: some description
 * </p>
 *
 * @author : xiaodong.yang
 * @date : 2024/6/19 18:32
 */
@Component
@Slf4j
public class ScriptRunner implements ApplicationRunner {

    @Value("classpath:/sql/init.sql")
    private Resource scriptResource;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        try {
//            // 读取资源文件内容
//            InputStreamReader reader = new InputStreamReader(scriptResource.getInputStream());
//            String scriptContent = FileCopyUtils.copyToString(reader);
//            log.info("初始化脚本:{}", scriptContent);
//            jdbcTemplate.execute(scriptContent);
//        } catch (Exception e) {
//            System.err.println("加载资源脚本失败：" + e.getMessage());
//        }
    }
}
